package csc.daonjpa.java.dao;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;

import org.springframework.stereotype.Repository;

import csc.daonjpa.java.beans.CustomerBean;
import csc.daonjpa.java.domain.Customer;

@Repository
public class CustomerDAO {

	@PersistenceContext
	private EntityManager entityManagerFactory;
	
	@Transactional
	public boolean authentication(CustomerBean cus) {
		
		String sql = "SELECT c FROM Customer WHERE c.loginId = :id AND c.password = :pass";
		TypedQuery<Customer> query = entityManagerFactory.createQuery(sql, Customer.class);
		query.setParameter("id", cus.getLoginId());
		query.setParameter("pass", cus.getPassword());
		
		Customer customer = query.getSingleResult();
		
		if (customer != null) {
			return true;
		}
		return false;
	}
}
